# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
	def error_messages_for(object_name, options = {})
		options = options.symbolize_keys
		object = instance_variable_get("@#{object_name}")
		unless object.errors.empty?
			error_lis = []
			object.errors.each{ |key,msg| error_lis << content_tag("li", msg) }
	
			content_tag("div",
			content_tag(options[:header_tag] || "h2","发生#{object.errors.count}个错误") +
			content_tag("ul", error_lis),
			"id" => options[:id] || "errorExplanation", "class" => options[:class] || "errorExplanation"
			)
		end
	end 
	
	def formatSaleNum(num,length)
		retNum = num.to_s
		if num.to_s.length < length
			(length-num.to_s.length).times do |i|
				retNum.insert(0,'0')
			end
		end
		retNum
	end
end
